package com.huwaiwai.fork_join.demo01;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;

/**
 * Created by huweiwei on 2017/4/14.
 */
public class Test {
    int time = 500000000;

    @org.junit.Test
    public void test01(){
        long start = System.currentTimeMillis();
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        MyRecursiveTask task = new MyRecursiveTask(1,time);
        Future<Integer> result = forkJoinPool.submit(task);
        try {
            System.out.println(result.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        System.out.println(System.currentTimeMillis() - start);
    }

    @org.junit.Test
    public void test02(){
        long start = System.currentTimeMillis();
        int sum = 0;
        for (int i = 0; i <= time; i++) {
            sum += i;
        }
        System.out.println(System.currentTimeMillis() - start + " " + sum);
    }




}
